function noPushCheck() {
	if($("#receiveCustom").attr("checked")==true) {
		$("#customerLowerLimit").attr("disabled","disabled");
		$("#repcustomerCount").attr("disabled","disabled");
		$("#customerLimit").attr("disabled","disabled");
		$("#isSysPush").attr("disabled","disabled");
		$("#isArtificialPush").attr("disabled","disabled");
		$("#receiveCustomHidden").val("1");
	}
	else {
		$("#customerLowerLimit").removeAttr("disabled");
		$("#repcustomerCount").removeAttr("disabled");
		$("#customerLimit").removeAttr("disabled");
		$("#isSysPush").removeAttr("disabled");
		$("#isArtificialPush").removeAttr("disabled");
		$("#receiveCustomHidden").val("0");
	}
}
$(document).ready(function() {
	var screenwidth, screenheight, mytop, getPosLeft, getPosTop
	screenwidth = $(window).width();
	screenheight = $(window).height();
	//获取滚动条距顶部的偏移
	mytop = $(document).scrollTop();
	//计算弹出层的left
	getPosLeft = screenwidth / 2 - 260;
	//计算弹出层的top
	getPosTop = screenheight / 2 - 150;
	//css定位弹出层
	$("#deptTree").css({ "left": getPosLeft, "top": getPosTop });
	$("#empSet").css({ "left": getPosLeft, "top": getPosTop });
	//当浏览器窗口大小改变时
	$(window).resize(function() {
		screenwidth = $(window).width();
		screenheight = $(window).height();
		mytop = $(document).scrollTop();
		getPosLeft = screenwidth / 2 - 200;
		getPosTop = screenheight / 2 - 150;
		$("#deptTree").css({ "left": getPosLeft, "top": getPosTop+ mytop  });
		$("#empSet").css({ "left": getPosLeft, "top": getPosTop+ mytop  });
	});
	//当拉动滚动条时，弹出层跟着移动
	$(window).scroll(function() {
		screenwidth = $(window).width();
		screenheight = $(window).height();
		mytop = $(document).scrollTop();
		getPosLeft = screenwidth / 2 - 200;
		getPosTop = screenheight / 2 - 150;
		$("#deptTree").css({ "left": getPosLeft, "top": getPosTop+ mytop  });	 
		$("#empSet").css({ "left": getPosLeft, "top": getPosTop+ mytop  });	 
	}); 
	 //获取页面文档的高度
	 var docheight = $(document).height();
	//追加一个层，使背景变灰
	$("body").append("<div id='greyBackGround'></div>");
	$("#greyBackGround").css({ "opacity": "0.1", "height": docheight });


	//条件查询		 
	$("#queryEmp").click(function(){
	 	$("#queryForm").submit();	
	});			 
	//清空			 		 
	$("#clean").click(function(){
		$("#empName")[0].value="";
		$("#contact")[0].value="";
		$("#mail")[0].value="";
		$("#roleId").val("");
		$("#queryDeptId").val("");
		$("#queryTempDeptId").val("");
	});
		 
	//账号设置确认按钮
	$("#confirmBtn").click(function(){
		var reg = /^[0-9]*[1-9][0-9]*$/;
		var repcustomerCount = $("#repcustomerCount")[0].value;
		if(repcustomerCount==null || repcustomerCount==""){
			alert("报备库容量,不能为空!");
			return;
		}else{
			if(!reg.test(repcustomerCount)){
				alert("报备库容量,输入有误,请重新输入!");
				return;
			}
		}
		var customerLimit = $("#customerLimit")[0].value;
		if(customerLimit==null || customerLimit==""){
			alert("人工推送上限,不能为空!");
			return;
		}else{
			if(!reg.test(customerLimit)){
				alert("人工推送上限,输入有误,请重新输入!");
				return;
			}
		}
		var customerLowerLimit = $("#customerLowerLimit")[0].value;
		if(customerLowerLimit==null || customerLowerLimit==""){
			alert("人工推送下限,不能为空!");
			return;
		}else{
			if(!reg.test(customerLowerLimit)){
				alert("人工推送下限,输入有误,请重新输入!");
				return;
			}	
		}
		if(parseInt(customerLowerLimit)>parseInt(customerLimit)){
			alert("推送下限不能大于推送上限,请重新输入!");
			return;
		}
		if($("#isSysPush").attr("checked")==true){
			 $("#sysPush").val("1");
		}else{
			 $("#sysPush").val("2");
		}
		if($("#isArtificialPush").attr("checked")==true){
			 $("#artificialPush").val("1");
			
		}else{
			 $("#artificialPush").val("2");
		}
		if($("#receiveCustom").attr("checked")==true) {
			$("#customerLowerLimit").attr("disabled","disabled");
			$("#repcustomerCount").attr("disabled","disabled");
			$("#customerLimit").attr("disabled","disabled");
			$("#isSysPush").attr("disabled","disabled");
			$("#isArtificialPush").attr("disabled","disabled");
			$("#receiveCustomHidden").val("1");
		}else{
			$("#receiveCustomHidden").val("0");
		}
		 $.ajax({
			 type: "POST",
	         url:"../../ruleSet/employeeSet/updateEmp",
	         data:$('#updateEmpForm').serialize(),
	         async: false,
	         error: function(request){
	        	 location.reload();
	        	 $("#empno")[0].value="";
	        	 $("#empnoStr")[0].value="";
	        	 $("#repcustomerCount")[0].value="";
	        	 $("#customerLimit")[0].value="";
	        	 $("#customerLowerLimit")[0].value="";
	        	 $("#sysPush")[0].value="";
	        	 $("#artificialPush")[0].value="";
	        	 $("#receiveCustomHidden")[0].value="";
	        	 $("#isSysPush").attr("checked",false); 
	        	 $("#isArtificialPush").attr("checked",false); 
	        	 $("#receiveCustom").attr("checked",false); 
	        	 $("#bathConfirmBtn").css("display","none");
	         },
	         success: function(data){
	        	 location.reload();
	        	 $("#empno")[0].value="";
	        	 $("#empnoStr")[0].value="";
	        	 $("#repcustomerCount")[0].value="";
	        	 $("#customerLimit")[0].value="";
	        	 $("#customerLowerLimit")[0].value="";
	        	 $("#receiveCustomHidden")[0].value="";
	        	 $("#sysPush")[0].value="";
	        	 $("#artificialPush")[0].value="";
	        	 $("#isSysPush").attr("checked",false); 
	        	 $("#isArtificialPush").attr("checked",false); 
	        	 $("#receiveCustom").attr("checked",false); 
	        	 $("#bathConfirmBtn").css("display","none");
	         }
	    });	
	});
	//账号批量设置确认按钮
	$("#bathConfirmBtn").click(function(){

		var reg = /^[0-9]*[1-9][0-9]*$/;
		var repcustomerCount = $("#repcustomerCount")[0].value;
		if(repcustomerCount==null || repcustomerCount==""){
			alert("报备库容量,不能为空!");
			return;
		}else{
			if(!reg.test(repcustomerCount)){
				alert("报备库容量,输入有误,请重新输入!");
				return;
			}
		}
		var customerLimit = $("#customerLimit")[0].value;
		if(customerLimit==null || customerLimit==""){
			alert("人工推送上限,不能为空!");
			return;
		}else{
			if(!reg.test(customerLimit)){
				alert("人工推送上限,输入有误,请重新输入!");
				return;
			}
		}
		var customerLowerLimit = $("#customerLowerLimit")[0].value;
		if(customerLowerLimit==null || customerLowerLimit==""){
			alert("人工推送下限,不能为空!");
			return;
		}else{
			if(!reg.test(customerLowerLimit)){
				alert("人工推送下限,输入有误,请重新输入!");
				return;
			}	
		}
		if(parseInt(customerLowerLimit)>parseInt(customerLimit)){
			alert("推送下限不能大于推送上限,请重新输入!");
			return;
		}
		if($("#isSysPush").attr("checked")==true){
			 $("#sysPush").val("1");
		}else{
			 $("#sysPush").val("2");
		}
		if($("#isArtificialPush").attr("checked")==true){
			 $("#artificialPush").val("1");
			
		}else{
			 $("#artificialPush").val("2");
		}
		if($("#receiveCustom").attr("checked")==true) {
//			$("#customerLowerLimit").attr("disabled","disabled");
//			$("#repcustomerCount").attr("disabled","disabled");
//			$("#customerLimit").attr("disabled","disabled");
//			$("#isSysPush").attr("disabled","disabled");
//			$("#isArtificialPush").attr("disabled","disabled");
			$("#receiveCustomHidden").val("1");
		}else{
			$("#receiveCustomHidden").val("0");
		}
		$('#updateEmpForm').attr("action","../../ruleSet/employeeSet/bathUpdateEmp");
		$('#updateEmpForm').submit();
/*		 $.ajax({
			 type: "POST",
	         url:"../../ruleSet/employeeSet/bathUpdateEmp",
	         data:$('#updateEmpForm').serialize(),
	         async: false,
	         error: function(request){
	        	 location.reload();
	        	 $("#empno")[0].value="";
	        	 $("#empnoStr")[0].value="";
	        	 $("#repcustomerCount")[0].value="";
	        	 $("#customerLimit")[0].value="";
	        	 $("#customerLowerLimit")[0].value="";
	        	 $("#sysPush")[0].value="";
	        	 $("#artificialPush")[0].value="";
	        	 $("#isSysPush").attr("checked",false); 
	        	 $("#isArtificialPush").attr("checked",false);
	         },
	         success: function(data){
	        	 location.reload();
	        	 $("#empno")[0].value="";
	        	 $("#empnoStr")[0].value="";
	        	 $("#repcustomerCount")[0].value="";
	        	 $("#customerLimit")[0].value="";
	        	 $("#customerLowerLimit")[0].value="";
	        	 $("#sysPush")[0].value="";
	        	 $("#artificialPush")[0].value="";
	        	 $("#isSysPush").attr("checked",false); 
	        	 $("#isArtificialPush").attr("checked",false); 
	         }
	    });*/
	});
	//账号设置取消按钮
	$("#cancelBtn").click(function(){
		 $("#greyBackGround").css("display","none");
		 $("#empSet").css("display","none");
    	 $("#empno")[0].value="";
    	 $("#empnoStr")[0].value="";
    	 $("#repcustomerCount")[0].value="";
    	 $("#customerLimit")[0].value="";
    	 $("#customerLowerLimit")[0].value="";
    	 $("#sysPush")[0].value="";
    	 $("#artificialPush")[0].value="";
    	 $("#isSysPush").attr("checked",false); 
    	 $("#isArtificialPush").attr("checked",false);
	});
	//批量设置按钮
	$("#bathEmployeeSet").click(function(){
		 var list = $("input[id^=empId_][type='checkbox']:checked");
		 if(list.length=="0"){
			 alert("请选择要批量设置的员工!");
			 return;
		 }
		 var empnoStr = "";
		 for ( var int = 0; int < list.length; int++) {
			 var empId =  list[int].value;
			 if(int==0){
				 empnoStr=empId;
			 }else{
				 empnoStr=empnoStr+","+empId; 
			 }	
		} 
		$("#empnoStr")[0].value= empnoStr;
		$("#confirmBtn").css("display","none");
		$("#bathConfirmBtn").css("display","block");
		$("#empSet").css("display","none");
    	$("#empno")[0].value="";
    	$("#repcustomerCount")[0].value="";
    	$("#customerLimit")[0].value="";
    	$("#customerLowerLimit")[0].value="";
    	$("#receiveCustomHidden")[0].value="0";
    	$("#sysPush")[0].value="";
    	$("#artificialPush")[0].value="";
    	$("#receiveCustom").attr("checked",false);
    	$("#isSysPush").attr("checked",false); 
    	$("#isArtificialPush").attr("checked",false);
 		$("#greyBackGround").css("display","block");
		$("#empSet").fadeIn("slow");
	});
	
	
	
	 $("#deptTreeBtnCancel").click(function(){
		 	$("#greyBackGround").css("display","none");
		 	$("#deptTree").css("display","none");
	});
	$("#queryDeptTreeBtnConfirm").click(function(){
		var selectedNodeId="";
		var selectedNodeName="";
		var treeObj=$.fn.zTree.getZTreeObj("treeDemo");
		nodes=treeObj.getSelectedNodes();
		 for ( var int = 0; int < nodes.length; int++){
			 var node = nodes[int];
			 selectedNodeId = node.id;
			 selectedNodeName = node.name;
			 break;
		} 
	     if(selectedNodeId==""){
	     	alert("请选择部门!");
	     	return;
	     }
		$("#queryDeptId").val(selectedNodeId);
		$("#queryTempDeptId").val(selectedNodeName);
	 	$("#greyBackGround").css("display","none");
	 	$("#deptTree").css("display","none");
	});
	
	var setting = {	
			view: {selectedMulti:false},data: {keep: {parent:true,leaf:true},simpleData: {enable: true}},
			callback: {beforeDrag: beforeDrag}
	};
	function beforeDrag(treeId, treeNodes){
		return false;
	}
	$.fn.zTree.init($("#treeDemo"), setting, zNodes);
});




function employeeSet(empno,repcustomerCount,customerLimit,customerLowerLimit,isSysPush,isArtificialPush,receiveCustom){
	 $("#greyBackGround").css("display","block");
	 $("#empSet").fadeIn("slow");
	 $("#empno").val(empno);
	 $("#repcustomerCount").val(repcustomerCount);
	 $("#customerLimit").val(customerLimit);
	 $("#customerLowerLimit").val(customerLowerLimit); 
	 $("#isSysPush").val(isSysPush); 
	 if(isSysPush==1){
		 $("#isSysPush").attr("checked",true); 
		 $("#sysPush").val("1");
	 }else{
		 $("#isSysPush").attr("checked",false); 
		 $("#sysPush").val("0");
	 }
	 $("#isArtificialPush").val(isArtificialPush); 
	 if(isArtificialPush==1){
		 $("#isArtificialPush").attr("checked",true); 
		 $("#artificialPush").val("1");
	 }else{
		 $("#isArtificialPush").attr("checked",false); 
		 $("#artificialPush").val("0");
	 }
	 if(receiveCustom==1) {
		 $("#receiveCustom").attr("checked",true); 
	 }else{
		 $("#receiveCustom").attr("checked",false); 
	 }
}

function queryDeptTree(){
	 $("#queryDeptTreeBtnConfirm").css("display","block");
	 $("#greyBackGround").css("display","block");
	 $("#deptTree").fadeIn("slow"); 
}
function selectAll(){
	if($("#selectAll").attr("checked")==true){
		$('input[id^=empId_]').attr("checked",true); 
	}else{
		$('input[id^=empId_]').attr("checked",false); 
		
	}
}

function clearSurplusLimit() {
	$("#waitDiv").fadeIn(100);
	var timeUp=$("#timeUp").val();
	var timeDown=$("#timeDown").val();
	$.ajax({
		type:"POST",
		dataType:"text",
		data:{"timeUp":timeUp,"timeDown":timeDown},
		url:"../../authority/employee/clearSurplusLimit",
		success:function(msg) {
			if(msg==1) {
				alert("操作完成");
			}
			else {
				alert("操作失败");
			}
			$("#waitDiv").fadeOut(100);
		}
	});
}
